package com.weimob.mcloud.wechatwork.customer.mq.handler.losemsg;

import com.weimob.mcloud.wechatwork.core.base.MultiResponse;
import com.weimob.mcloud.wechatwork.core.entity.privatesphere.PrivateSphere;
import com.weimob.mcloud.wechatwork.core.entity.relation.task.Task;
import com.weimob.mcloud.wechatwork.core.enums.task.TaskBizTypeEnum;
import com.weimob.mcloud.wechatwork.core.service.lbl.TaskService;
import com.weimob.mcloud.wechatwork.core.service.task.request.SingleTaskAttachRequest;
import com.weimob.mcloud.wechatwork.customer.domain.CustomerTouchInfo;
import com.weimob.soa.common.response.SoaResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 企业群发
 * Create Time: 2022年05月23日 10:12
 *
 * @author maosheng.li
 **/
@Service
@Slf4j
public class SendTaskTouchImpl implements CustomerTouchService{

    @Resource
    private TaskService taskService;

    @Override
    public CustomerTouchInfo getCustomerTouchInfo(PrivateSphere privateSphere, CustomerTouchInfo touchInfoRequest) {
        CustomerTouchInfo result = new CustomerTouchInfo();
        result.setTaskId(touchInfoRequest.getTaskId());
        Task task = new Task();
        task.setTaskId(touchInfoRequest.getTaskId());
        task.setBizType(TaskBizTypeEnum.GROUP_SEND);
        SingleTaskAttachRequest<Task> request = new SingleTaskAttachRequest();
        request.setData(task);
        request.setPrivateSphere(privateSphere);
        SoaResponse<MultiResponse<Task>, ?> multiResponseSoaResponse = taskService.fetchTask(request);
        MultiResponse<Task> responseVo = multiResponseSoaResponse.getResponseVo();
        if(responseVo != null && CollectionUtils.isNotEmpty(responseVo.getDataList())){
            Task taskResult = responseVo.getDataList().get(0);
            result.setTaskName(taskResult.getTaskName());
        }
        return result;
    }
}
